﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ArduinoSketch.Core
{
    public static class StringConst
    {
        public const string NEW_DOCUMENT_TEXT = "Untitled";
        public const int LINE_NUMBERS_MARGIN_WIDTH = 35; // TODO Don't hardcode this

        /// <summary>
        /// 0=mcu 
        /// 1=df_cpu 
        /// 2=arduino path 
        /// 3=file name
        /// 4=applet path
        /// 5=file name
        /// </summary>
        public const string STD_ARDUINO_LIB_GCC =
            @"-c -g -Os -w -ffunction-sections -fdata-sections -mmcu={0} -DF_CPU={1} {2} {3} -o{4}";

        /// <summary>
        /// 0=mcu 
        /// 1=df_cpu 
        /// 2=arduino path 
        /// 3=arduino path 
        /// 4=file name
        /// 5=applet path
        /// 6=file name
        public const string STD_ARDUINO_LIB_GPP =
            @"-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu={0} -DF_CPU={1} {2} {3} -o{4}";

        /// <summary>
        /// 0=applet path, 
        /// 1=applet path
        /// </summary>
        public const string STD_LINKING_LIB = "rcs {0}libcore.a {1}";

        /// <summary>
        /// 0=mcu, 
        /// 1=df_cpu, 
        /// 2=include path, 
        /// 3=file name, 
        /// 4=filename
        /// </summary>
        public const string BUILD_SKETCH = 
            "-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu={0} -DF_CPU={1} {2} {3} -o{4}";

        /// <summary>
        /// 0=mcu,
        /// 1=df_cpu
        /// 2=inclide directory
        /// 3=file name
        /// 4=object file name
        /// </summary>
        public const string GCC_INCLUDE_LIB =
            @"-c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu={0} -DF_CPU={1} {2} {3} -o{4}";

        /// <summary>
        /// 0=mcu,
        /// 1=df_cpu
        /// 2=inclide directory
        /// 3=file name
        /// 4=object file name
        /// </summary>
        public const string GPP_INCLUDE_LIB =
            @"-c -g -Os -w -ffunction-sections -fdata-sections -mmcu={0} -DF_CPU={1} {2} {3} -o{4}";

        /// <summary>
        ///
        /// </summary>
        public const string GPP_LIMKER =
            "-Os -Wl,--gc-sections -mmcu={0} -o{1}.elf {2} -L{3} -lcore -lm";

        /// <summary>
        /// 0-file name,
        /// 1=file name
        /// </summary>
        public const string CREATE_FLASH_IMAGE =
            "-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 {0}.elf {1}.eep ";

        /// <summary>
        /// 0-file name,
        /// 1=file name
        public const string CREATE_EEPROM_IMAGE =
            "-O ihex -R .eeprom {0}.elf  {1}.hex ";

        /// <summary>
        /// 
        /// </summary>
        public const string PRINT_SIZE =
            "--format=avr --mcu={0} {1}.elf";

        /// <summary>
        /// 
        /// </summary>
        public static string ARDU_TARGET_CNFG = String.Format(@"{0}\{1}", Application.StartupPath, "ArduinoTargetConfig.cfg");

        /// <summary>
        /// 
        /// </summary>
        public static string BOARD_CNFG = String.Format(@"{0}\{1}", Application.StartupPath, "Board.cfg");

        /// <summary>
        /// 
        /// </summary>
        public static string PROGRAMERS = String.Format(@"{0}\{1}", Application.StartupPath, "Programers.cfg");

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string BuildGccCommand(object[] param)
        {
            string _command = string.Format(StringConst.STD_ARDUINO_LIB_GCC, param);

            return _command;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string BuildGppCommand(object[] param)
        {
            string _command = string.Format(StringConst.STD_ARDUINO_LIB_GPP, param);

            return _command;
        }

        public static string LinkingCommand(object[] param)
        {
            string _command = string.Format(StringConst.STD_LINKING_LIB, param);

            return _command;
        }

        public static string BuildSkethCommand(object[] param)
        {
            string _command = string.Format(StringConst.BUILD_SKETCH, param);

            return _command;
        }

        public static string DefaultPdeFile()
        {
            StringBuilder _builder = new StringBuilder();
            _builder.AppendLine("/*");
            _builder.AppendLine(" * Create Date Time: " + DateTime.Now.ToString());
            _builder.AppendLine(" *");
            _builder.AppendLine(" */");
            _builder.AppendLine();
            _builder.AppendLine();
            _builder.AppendLine("void setup()");
            _builder.AppendLine("{");
            _builder.AppendLine();
            _builder.AppendLine("}");
            _builder.AppendLine();
            _builder.AppendLine("void loop()");
            _builder.AppendLine("{");
            _builder.AppendLine();
            _builder.AppendLine("}");
            _builder.AppendLine();
            _builder.AppendLine();

            return _builder.ToString();
        }
    }
}
